Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Handling for HTTP Status Codes #67

Merged
merged 10 commits into from
Jul 31, 2020

Conversation

arcanearronax
Copy link
Contributor

Added error handling based on HTTP status codes. The status codes identified after submitting the GET request for the URL will produce a handling code which informs the cli method how it should proceed, either exiting the application or retrying the request. A message will be displayed to inform the user of the nature of the error or that a retry will occur in a given amount of time.

Context
This will prevent errors originating from unsuccessful requests from reaching the user.

Description

Added a request validation method to search.py which both search and search_github_trending call when submitting a GET request. This will catch a connection error and raise an assertion error in the case of an HTTP status code indicating something other than a success. Added a search_error method which processes the assertion error and returns the appropriate handling code for the assertion error.

A while loop has been added to the cli method which contains the calls to search and search_github_trending in order to allow requests to be resubmitted (if appropriate) and messages are printed for the user to indicate the nature of the issue, based on the handling code.

…than a success and to catch and handle that result, either by resubmitting the request after a delay or exiting with a relevant message. Handling codes were added to search.py in order to identify how each HTTP status code should be handled. The handling of these codes occur within __main__.py.
…te the submitted requests and modified __main__.py to catch assertion errors for both search methods, and to retry if the handling code indicates that should happen.
@hedyhli
Copy link
Owner

hedyhli commented Jul 28, 2020

Sorry for the delayed response BTW, I was busy with some school work

hedyhli and others added 6 commits July 28, 2020 19:07
…than a success and to catch and handle that result, either by resubmitting the request after a delay or exiting with a relevant message. Handling codes were added to search.py in order to identify how each HTTP status code should be handled. The handling of these codes occur within __main__.py.
…te the submitted requests and modified __main__.py to catch assertion errors for both search methods, and to retry if the handling code indicates that should happen.
…starcli into additional_error_handling

Modified the search and search_github_trending methods to return None if request is None.
@hedyhli
Copy link
Owner

hedyhli commented Jul 30, 2020

Do you think having a dict of status codes, instead of a bunch of STATUS_ variables will be better? Because then this will be easily extendable in the future for adding more codes, and we only need to import something like a STATUS_CODES dict

@hedyhli
Copy link
Owner

hedyhli commented Jul 30, 2020

It's totally fine to keep it as is if you don't want to change it though, because search_error() kind of acts as a 'dict' here, the only downside is we need to import a lot of variables

@arcanearronax
Copy link
Contributor Author

You're right about using a dict rather than creating a handful of variables, and it'll be able to scale easier. I'm not sure why I didn't think of it at the time. I'll get the changes made here in a bit.

…as modified to use a dict containing the different handling codes and the messages that should be printed if the code is encountered.
Copy link
Owner

@hedyhli hedyhli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 looks great!

@hedyhli hedyhli merged commit 75c37e6 into hedyhli:main Jul 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants